package io.sage.common.config;

import com.alibaba.fastjson.JSONObject;
import io.sage.common.utils.Config;
import io.sage.common.utils.HttpUtil;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 验证码通知短信接口
 * 
 * @ClassName: IndustrySMS
 * @Description: 验证码通知短信接口
 *
 */
public class IndustrySMS
{
	private static String operation = "/industrySMS/sendSMS";
	private static String accountSid = Config.ACCOUNT_SID;
//	private static String to = "17600377390";
	//private static String sig = "【sage考试系统】";
//	private static String smsContent = sig+"登录验证码：123，如非本人操作，请忽略此短信。";

	/**
	 * 验证码通知短信,
	 * operation = "/industrySMS/sendSMS";
	 * accountSid = Config.ACCOUNT_SID;
	 * to = "17600377390";
	 * sig = "【sage考试系统】";
	 * smsContent = sig+"登录验证码：123，如非本人操作，请忽略此短信。";
	 */
	public static String execute(String to,String code,String templateid)
	{
		
		String smsContent=code;
		String tmpSmsContent = null;
	    try{
	      tmpSmsContent = URLEncoder.encode(smsContent, "UTF-8");
	    }catch(Exception e){
	      
	    }
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
	    sdf.format(new Date());
	    String url = Config.BASE_URL ;
	    String body = "accountSid=" + Config.ACCOUNT_SID + "&to=" + to + "&templateid="+templateid+"&param=" + tmpSmsContent
	        + HttpUtil.createCommonParam();

	    // 提交请求
	    String result = HttpUtil.post(url, body);
//	    System.out.println("result:" + System.lineSeparator() + result);
		System.out.println(result);
		return result;
	}
	/**
	 * 语音通知
	 * 20141029/accounts/823deef8e529477185a52179325b4a62/call/voiceTemplateNotify?sig=84b81c1d13911dd6cd35e63b4db988e8&timestamp=20141116113918
	 */
	public static String executeMusic(String to,String code,String templateid)
	{

		String smsContent=code;
		String tmpSmsContent = null;
	    try{
	      tmpSmsContent = URLEncoder.encode(smsContent, "UTF-8");
	    }catch(Exception e){

	    }
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
	   ;
	    String url = Config.BASE_URL_VIDEO  +Config.ACCOUNT_SID_VIDEO+"/call/voiceTemplateNotify?"+ HttpUtil.createCommonParamB();

		JSONObject jsonObject=new JSONObject();
		JSONObject obj=new JSONObject();
		obj.put("callee", to);
		obj.put("templateId", 1562);
		obj.put("param", code);
		jsonObject.put("voiceTemplate", obj);
		String body = jsonObject.toJSONString();


	    // 提交请求
	    String result = HttpUtil.postVideo(url, body);
//	    System.out.println("result:" + System.lineSeparator() + result);
		System.out.println(result);
		return result;
	}
	public static void main(String[] args) {
		//IndustrySMS.executeMusic("17777793421", "一号库房","172462");
	}
}
